package cn.iocoder.mall.product.dao;

import cn.iocoder.mall.product.entities.CommoditySpu;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.io.Serializable;
import java.util.List;

/**
 * @Description: 商品SPU
 * @Author: jeecg-boot
 * @Date:   2019-11-07
 * @Version: V1.0
 */
public interface CommoditySpuMapper extends BaseMapper<CommoditySpu> {

    /**
     * 删除一对多--更新
     * @param id
     */
    @Update("update product_spu set deleted = 1 where id = #{id} ")
     boolean deleteSpuById(@Param("id") Serializable id);


    /**
     * 修改商品审核状态
     * @param id
     */
    @Update("update product_spu set to_examine = #{toExamine} where id = #{id} ")
    boolean updateToExamine(@Param("id") Long id,@Param("toExamine")Integer toExamine);
    /**
     * 批量修改商品审核状态
     */
    boolean  batchUpdateToExamine(@Param("list") List<Long> list,@Param("toExamine")String toExamine);

    /**
     * 修改商品上下架状态
     */
    boolean changeProductSpuVisible(@Param("visible")Boolean visible ,@Param("id")Long id);

    /**
     * 批量修改商品上下架状态
     */
    boolean batchChangeProductSpuVisible(@Param("visible")Boolean visible ,@Param("ids")List<Long> id);

    /**
     * 管理端删除商品
     * @param asList
     */
    void deleteBySpuId(@Param("idList") List<String> asList);
    /**
     * 获取單個店铺的所有商品
     * @param page
     * @param id
     * @return
     */
     List<CommoditySpu> getShopPageListOfShop(Page page, @Param("id") String id);
    /**
     * 通过spuid获取单个商品的信息，spu+ 一到多个sku
     * @param id
     * @return
     */
    CommoditySpu getCommoditySpuDetails(@Param("id") Long id);


    IPage<CommoditySpu> getShopPageList(Page page, @Param(Constants.WRAPPER)QueryWrapper<CommoditySpu> queryWrapper);

    /**
     * 判断商品审核状态 true :通过 false: 未通过
     * @param spuId
     * @return
     */
    @Select("select to_examine from product_spu where id =#{spuId}")
    CommoditySpu judgeOneExamine(@Param("spuId") String spuId);

    CommoditySpu getOneShopDetailsBySkuId(@Param("id") Long id);
    /**
     * 通过商品id 获取对应的商户id
     * @param asList
     * @return
     */
    List<CommoditySpu> getAllSellerId(@Param("asList") List<String> asList);
}
